package com.cnzha.mr.wordcount;

import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * @Author: zhaoxin
 * @email: zdkk@foxmail.com
 * @Date: 3/31/2020 10:59 AM
 */
public class WordCountMapper extends Mapper<LongWritable, Text, Text, IntWritable> {


    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        Text k = new Text();
        IntWritable intWritable = new IntWritable(1);

        String s = value.toString();
        String[] sArr = s.split(" ");
        for (String s1 : sArr) {
            k.set(s1);
            context.write(k, intWritable);
        }
    }
}
